import { makeAutoObservable, computed, observable, action } from "mobx";

import Test from "./test";

export default class Todo {
  constructor(testStore: Test) {
    this.testStore = testStore;
    makeAutoObservable(this, {
      counter: observable,
      increment: action,
      reset: action,
      getCounter: computed,
    });
  }

  testStore: Test;
  counter: number = 0;

  get getCounter() {
    return this.counter * 2;
  }

  increment(): void {
    setTimeout(() => {
      Promise.resolve().then(() => {
        this.counter++;
      });
    }, 1000);
  }

  reset(): void {
    this.testStore.setTitle("title");
    this.counter = 0;
  }
}
